import request from "@/utils/request";

export type AddCartParams = {
  userid: string;
  proid: string;
  num: number;
};

/**
 * 将商品添加至购物车
 * @param data 入参
 * @returns
 */
export function addCart(data: AddCartParams) {
  return request({
    url: "/api/cart/add",
    method: "POST",
    data,
  });
}

/**
 * 获取购物车列表数据
 * @param userid 用户Id
 * @returns
 */
export function getCartList(userid: string) {
  return request({
    url: "/api/cart/list",
    method: "POST",
    data: {
      userid,
    },
  });
}

/**
 * 更新购物车某个商品的勾选状态
 * @param cartid 购物车Id
 * @param flag 是否勾选
 * @returns
 */
export function updateChecked(cartid: string, flag: boolean) {
  return request({
    url: "/api/cart/selectone",
    method: "POST",
    data: {
      cartid,
      flag,
    },
  });
}

/**
 * 更新购物车所有商品的勾选状态
 * @param userid 用户id
 * @param type 状态
 * @returns
 */
export function updateCheckedAll(userid: string, type: boolean) {
  return request({
    url: "/api/cart/selectall",
    method: "POST",
    data: {
      userid,
      type,
    },
  });
}

/**
 * 更新购物车某个商品的数量
 * @param cartid 购物车Id
 * @param num 数量
 * @returns
 */
export function updateNum(cartid: string, num: number) {
  return request({
    url: "/api/cart/updatenum",
    method: "POST",
    data: {
      cartid,
      num,
    },
  });
}
